//
//  ViewController.m
//  AVSpeech
//
//  Created by Xwoder on 17/1/23.
//  Copyright © 2017年 Xwoder. All rights reserved.
//

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface ViewController ()

@property (nonatomic, strong) AVSpeechSynthesizer *synthesizer;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSArray<NSString *> *sentenceArr = @[@"你好世界", @"世界你好"];
    
    AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
    self.synthesizer = synthesizer;
    
    for (NSString *sentence in sentenceArr) {
        AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
        AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:sentence];
        utterance.voice = voice;
        utterance.rate = AVSpeechUtteranceDefaultSpeechRate;
        utterance.pitchMultiplier = 1;
        // utterance.preUtteranceDelay = 0.5;
        // utterance.postUtteranceDelay = 0.5;
        [synthesizer speakUtterance:utterance];
    }
}

@end
